﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Managers.*;
    import Classes.*;

    public class TConstructionFinish extends TWorldState {

        private var m_params:Object;
        protected var m_originalTrees:Array;

        public function TConstructionFinish(_arg1:ConstructionSite, _arg2:Array=null){
            var _local4:Array;
            var _local5:int;
            var _local6:Object;
            super(_arg1);
            this.m_params = {};
            this.m_params["mapOwner"] = Global.world.ownerId;
            this.m_params["itemId"] = _arg1.getId();
            this.m_params["wildernessData"] = new Array();
            if (_arg2 == null){
                _arg2 = [];
            };
            this.m_originalTrees = _arg2;
            var _local3:int;
            while (_local3 < _arg2.length) {
                _local4 = _arg2[_local3];
                _local5 = 0;
                this.m_params["wildernessData"][_local3] = new Array();
                for each (_local6 in _local4) {
                    this.m_params["wildernessData"][_local3][_local5] = {
                        x:_local6.x,
                        y:_local6.y,
                        dir:_local6.dir,
                        itemName:_local6.itemName,
                        id:_local6.id
                    };
                    _local5++;
                };
                _local3++;
            };
        }
        override public function perform():void{
            signedWorldAction("finish", this.m_params);
        }
        override protected function onWorldActionComplete(_arg1:Object):void{
            var _local2:Array;
            var _local3:int;
            var _local4:Array;
            var _local5:int;
            var _local6:int;
            var _local7:GameObject;
            var _local8:int;
            super.onWorldActionComplete(_arg1);
            if (_arg1 != null){
                _local2 = (_arg1["wildernessObjects"] as Array);
                if (!_local2){
                    return;
                };
                _local3 = 0;
                while (_local3 < _local2.length) {
                    _local4 = _local2[_local3];
                    if (!_local4){
                    } else {
                        _local5 = 0;
                        if (this.m_originalTrees[_local3].length == _local4.length){
                            _local6 = 0;
                            while (_local6 < this.m_originalTrees[_local3].length) {
                                _local7 = GameObject(this.m_originalTrees[_local3][_local6].wildernessObj);
                                if (_local7.getId() == _local4[_local6].id){
                                    _local8 = _local4[_local6].newId;
                                    if (_local8 != 0){
                                        _local7.setId(_local8);
                                        _local5++;
                                    };
                                };
                                _local6++;
                            };
                        };
                        if (_local5 != this.m_originalTrees[_local3].length){
                            ErrorManager.addError("Warning: TConstructionFinish failed to remap ids.");
                        };
                    };
                    _local3++;
                };
            };
        }

    }
}//package Transactions 
